<?php
namespace App\Youtube\Controllers;

require_once '../../../vendor/autoload.php';

use phpspider\core\phpspider;
use phpspider\core\requests;
use phpspider\core\selector;

/* Do NOT delete this comment */
/* 不要删除这段注释 */

$url = "https://www.youtube.com/user/AETV/about?disable_polymer=1";
$html = requests::get($url);

file_put_contents('./youtube_A&E_about.html',$html);

// 选择器规则
$selector = "//a[@class='spf-link branded-page-header-title-link yt-uix-sessionlink']";  //kol名
$name = selector::select($html, $selector);

$selector = "//span[@class='yt-subscription-button-subscriber-count-branded-horizontal subscribed yt-uix-tooltip']";  //粉丝量
$fans_nums = selector::select($html, $selector);

$selector = "//span[@class='about-stat']//b";  //浏览量
$view_count = selector::select($html, $selector);

$selector = "//div[@class='about-description branded-page-box-padding']//pre";  //kol描述
$description = selector::select($html, $selector);

$selector = "//span[@class='country-inline']";  //国籍
$country = selector::select($html, $selector);

$selector = "//meta[@itemprop='channelId']/@content";  //channel_id
$channel_id = selector::select($html, $selector);

$selector = "//span[@class='about-stat'][last()]";  //注册日期
$register_time = selector::select($html, $selector);

$selector = "//img[@class='appbar-nav-avatar']/@src";  //头像
$head_img = selector::select($html, $selector);

$data = array(
    'name' => str_replace('&amp;','&',$name),
    'fans_nums' => $fans_nums,
    'view_count' => $view_count,
    'description' => $description,
    'country' => trim($country),
    'channel' => trim($channel_id),
    'register_time'=>$register_time,
    'head_img'=>$head_img,
);

// 查看数据是否正常
print_r($data);





